unit uWin9605;

interface

uses
  winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.IOUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  uWinBase,
  uniBasicGrid,
  uniGridExporters,
  uniGUIBaseClasses,
  uniGUIClasses,
  uniToolBar,
  uniTreeView,
  uniDBGrid,
  uniSplitter,
  uniEdit,
  uniStrUtils,
  uniGUITypes,
  uniFileUpload;

type
  TWin9605 = class(TWinBase)
    tb1: TUniToolBar;
    dgDylaw: TUniDBGrid;
    btn1: TUniToolButton;
    btn2: TUniToolButton;
    btn3: TUniToolButton;
    edtKey: TUniEdit;
    btn4: TUniToolButton;
    fu: TUniFileUpload;
    procedure fuMultiCompleted(Sender: TObject; Files: TUniFileInfoArray);
    procedure btn4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure FraInit(const aJson: string = ''); override;
    procedure FraFree(); override;
  end;

var
  Win9605: TWin9605;

implementation

{$R *.dfm}

uses
  Uni,
  ServerModule,
  uniGUIUtils,
  uDmSys;

procedure TWin9605.btn4Click(Sender: TObject);
begin
  fu.execute;
end;

procedure TWin9605.FraFree;
begin
  inherited;
  dbqryfree(tuniquery(dgDylaw.datasource.dataset));
end;

procedure TWin9605.FraInit(const aJson: string);
begin
  inherited;
  dgLoad(dgDylaw, 'select * from oa_bylaw', []);
end;

procedure TWin9605.fuMultiCompleted(Sender: TObject; Files: TUniFileInfoArray);
var
  fName, fPath: string;
begin
  for var afile in Files do
  begin
    fPath := sysFile(Format('files\bylaw\%s%s', [sysrnd(16), ExtractFileExt(afile.filename)]), True);
    TFile.Copy(afile.CacheFile, fPath);
    dbSql('insert into oa_bylaw (bltitle,blpath,blcreateby) values(:t,:p,:u)', [afile.filename,
      sysUrl(fPath), UniSession.UserString])
  end;
end;

initialization
  registerclass(TWin9605);

end.

